var _class, _temp;

import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, getAvatar, servicePhoneNumber, subtime } from "../../utils/common";
import upgradeStyleSheet from "./upgrade_styles";
import right from "../../assets/img/right.png";
import check from "../../assets/img/icon_74.png";
import check_on from "../../assets/img/icon_74_on.png";
var _styleSheet = upgradeStyleSheet;

function _getClassName() {
  var className = [];
  var args = arguments[0];
  var type = Object.prototype.toString.call(args).slice(8, -1).toLowerCase();

  if (type === 'string') {
    args = args.trim();
    args && className.push(args);
  } else if (type === 'array') {
    args.forEach(function (cls) {
      cls = _getClassName(cls).trim();
      cls && className.push(cls);
    });
  } else if (type === 'object') {
    for (var k in args) {
      k = k.trim();

      if (k && args.hasOwnProperty(k) && args[k]) {
        className.push(k);
      }
    }
  }

  return className.join(' ').trim();
}

function _getStyle(classNameExpression) {
  var className = _getClassName(classNameExpression);

  var classNameArr = className.split(/\s+/);
  var style = [];

  if (classNameArr.length === 1) {
    style.push(_styleSheet[classNameArr[0].trim()]);
  } else {
    classNameArr.forEach(function (cls) {
      style.push(_styleSheet[cls.trim()]);
    });
  }

  return style;
}

let Company = (_temp = _class = class Company extends Component {
  constructor(props) {
    super(props);
    this.state = {
      memberType: [{
        id: 0,
        name: '普通用户'
      }, {
        id: 1,
        name: 'VIP会员'
      }, {
        id: 2,
        name: '代理商'
      }, {
        id: 3,
        name: '合伙人'
      }],
      memberTypeName: '',
      currentMemberType: 1,
      userInfo: getRuntime().getUserInfo() || {},
      amount: {}
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '会员升级' });
    let memberType = this.$router.params.id;
    let index = this.state.userInfo.agencyLevel;
    this.getAgencyAmount();
    this.setState({
      memberTypeName: this.state.memberType[index]['name'],
      currentMemberType: parseInt(memberType) || 1
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  // 获取升级费用
  getAgencyAmount() {
    let { userStore } = this.props.stores;
    userStore.getAgencyAmount({
      callback: res => {
        this.setState({
          amount: toJS(res)
        });
      }
    });
  }
  changeMemberType(id) {
    this.setState({
      currentMemberType: id
    });
  }
  // 升级购买
  buyAgent(level, amount) {
    let { userStore } = this.props.stores;
    let { memberType, userInfo } = this.state;
    if (level > 0 && level === userInfo.agencyLevel) {
      getRuntime().showToast(`您已经是${memberType[level]['name']}了, 无法再次购买~`);
      return;
    }
    userStore.agencyApply({
      form: {
        agencyLevel: level,
        agencyAmount: amount,
        payType: 1
      },
      callback: res => {
        getRuntime().wxPay(res, () => {
          // 更新缓存用户信息
          userInfo.agencyLevel = level;
          getRuntime().setStorage('user', userInfo);
          getRuntime().navigateTo('/pages/user/upgrade_pay_success');
        });
      }
    });
  }
  makePhone() {
    getRuntime().makePhoneCall(servicePhoneNumber);
  }
  render() {
    let { currentMemberType, userInfo, memberTypeName, amount } = this.state;
    return <View style={_styleSheet["my-my_upgrade"]}>
        <View style={_styleSheet["list-21-item"]}>
          <Image src={getAvatar(userInfo.avatar)} style={_styleSheet["img"]} />
          <View style={_styleSheet["info"]}>
            <View style={_styleSheet["list-title"]}>{userInfo.name}
              <Text style={_styleSheet["list-label"]}>{memberTypeName}</Text>
            </View>
            <View style={_styleSheet["list-info"]}>
              {userInfo.agencyLevel === 1 && <Text>VIP会员至：{subtime(userInfo.endDateTime)}</Text>}
              {userInfo.agencyLevel === 2 && <Text>代理商至：{subtime(userInfo.endDateTime)}</Text>}
              {userInfo.agencyLevel === 3 && <Text>合伙人至：{subtime(userInfo.endDateTime)}</Text>}
            </View>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/user/buy_log')} style={_styleSheet["r"]}>
            <View style={_styleSheet["list-desc"]}>购买记录</View>
            <Image src={right} style={_styleSheet["icon-drop-down"]} />
          </View>
        </View>

        <View style={_styleSheet["interval"]} />

        <View style={_styleSheet["member-upgrade-wrap"]}>

          <View onClick={this.changeMemberType.bind(this, 1)} style={_getStyle(currentMemberType === 1 ? 'item-member-upgrade item-member-upgrade-active' : 'item-member-upgrade')}>
            <View style={_styleSheet["list-title"]}>建务通VIP会员</View>
            <View style={_styleSheet["info"]}>
              <View style={_styleSheet["l"]}>
                <Text style={_styleSheet["money"]}>{amount.normalAmount}</Text>
                <Text style={_styleSheet["small"]}>元/年</Text>
                <Text style={_styleSheet["old-price"]}>原价 ￥{amount.oldNormalAmount}</Text>
              </View>
              {currentMemberType === 1 && <Image src={check_on} style={_styleSheet["img"]} />}
              {currentMemberType !== 1 && <Image src={check} style={_styleSheet["img"]} />}
            </View>
          </View>

          <View onClick={this.changeMemberType.bind(this, 2)} style={_getStyle(currentMemberType === 2 ? 'item-member-upgrade item-member-upgrade-active' : 'item-member-upgrade')}>
            <View style={_styleSheet["list-title"]}>建务通代理商</View>
            <View style={_styleSheet["info"]}>
              <View style={_styleSheet["l"]}>
                <Text style={_styleSheet["money"]}>{amount.twoAmount}</Text>
                <Text style={_styleSheet["small"]}>元/年</Text>
                <Text style={_styleSheet["old-price"]}>原价 ￥{amount.oldTwoAmount}</Text>
              </View>
              {currentMemberType === 2 && <Image src={check_on} style={_styleSheet["img"]} />}
              {currentMemberType !== 2 && <Image src={check} style={_styleSheet["img"]} />}
            </View>
          </View>

          <View onClick={this.changeMemberType.bind(this, 3)} style={_getStyle(currentMemberType === 3 ? 'item-member-upgrade item-member-upgrade-active' : 'item-member-upgrade')}>
            <View style={_styleSheet["list-title"]}>建务通合伙人</View>
            <View style={_styleSheet["info"]}>
              <View style={_styleSheet["l"]}>
                <Text style={_styleSheet["money"]}>{amount.oneAmount}</Text>
                <Text style={_styleSheet["small"]}>元/年</Text>
                <Text style={_styleSheet["old-price"]}>原价 ￥{amount.oldOneAmount}</Text>
              </View>
              {currentMemberType === 3 && <Image src={check_on} style={_styleSheet["img"]} />}
              {currentMemberType !== 3 && <Image src={check} style={_styleSheet["img"]} />}
            </View>
          </View>

        </View>


        <View style={_styleSheet["upgrade-title"]}>
          <Text style={_styleSheet["line"]} />
          {currentMemberType === 1 && <Text style={_styleSheet["title"]}> 会员特权说明 </Text>}
          {currentMemberType === 2 && <Text style={_styleSheet["title"]}> 代理商特权说明 </Text>}
          {currentMemberType === 3 && <Text style={_styleSheet["title"]}> 合伙人特权说明 </Text>}

          <Text style={_styleSheet["line"]} />
        </View>
        <View onClick={this.makePhone.bind(this)} style={_styleSheet["tel"]}>
          <Text style={_styleSheet["s"]}>咨询热线： {servicePhoneNumber}</Text>
        </View>
        {currentMemberType === 1 && <View style={_styleSheet["upgrade-desc"]}>
             <View>一、团队累计达100位VIP。</View>
             <View>二、直接推荐VIP奖励100元/位，间接推荐VIP奖励40元/位，团队VIP服务奖20元/位。</View>
             <View>三、自用及直推会员还款万20奖励，会员团队还款万10奖励，VIP团队万5奖励。</View>
             <View>四、团队服务奖励，直接会员团队3%，VIP团队2%，直推代理2%。</View>
             <View>五、条件：直推3位VIP。</View>
          </View>}
        {currentMemberType === 2 && <View style={_styleSheet["upgrade-desc"]}>
             <View>一、代理商。</View>
             <View>一、团队累计达100位VIP。</View>
             <View>二、直接推荐VIP奖励100元/位，间接推荐VIP奖励40元/位，团队VIP服务奖20元/位。</View>
             <View>三、自用及直推会员还款万20奖励，会员团队还款万10奖励，VIP团队万5奖励。</View>
             <View>四、团队服务奖励，直接会员团队3%，VIP团队2%，直推代理2%。</View>
             <View>五、条件：直推3位VIP。</View>
          </View>}
        {currentMemberType === 3 && <View style={_styleSheet["upgrade-desc"]}>
             <View>一、合伙人。</View>
             <View>一、团队累计达100位VIP。</View>
             <View>二、直接推荐VIP奖励100元/位，间接推荐VIP奖励40元/位，团队VIP服务奖20元/位。</View>
             <View>三、自用及直推会员还款万20奖励，会员团队还款万10奖励，VIP团队万5奖励。</View>
             <View>四、团队服务奖励，直接会员团队3%，VIP团队2%，直推代理2%。</View>
             <View>五、条件：直推3位VIP。</View>
          </View>}


        <View style={_styleSheet["footer-block"]} />

        <View>
          {currentMemberType === 1 && <View onClick={this.buyAgent.bind(this, 1, amount.normalAmount)} style={_styleSheet["page-submit"]}>立即以{amount.normalAmount}元成为会员</View>}
          {currentMemberType === 2 && <View onClick={this.buyAgent.bind(this, 2, amount.twoAmount)} style={_styleSheet["page-submit"]}>立即以{amount.twoAmount}升级为代理商</View>}
          {currentMemberType === 3 && <View onClick={this.buyAgent.bind(this, 3, amount.oneAmount)} style={_styleSheet["page-submit"]}>立即以{amount.oneAmount}升级为合伙人</View>}
        </View>
      </View>;
  }
}, _class.config = {
  navigationBarTitleText: '会员升级'
}, _temp);
Company = tslib_1.__decorate([inject("stores"), observer], Company);
export default Company;